package com.aeye.mbr.ws;

import com.alibaba.dubbo.rpc.service.GenericService;

/**
 * Created by Administrator on 2018/1/15.
 */
public class ServiceInvoker {
    private GenericService service;
    private String method;

    public ServiceInvoker(GenericService service, String method) {
        this.service = service;
        this.method = method;
    }

    public ServiceInvoker(GenericService service) {
        this.service = service;
        this.method = method;
    }

    public Object invoke(Object... para){
        if(null == method){
            throw new RuntimeException("please specific method name");
        }
        String[] paramTypes = new String[para.length];
        for(int i =0; i < para.length; i++)
        {
            paramTypes[i] = para[i].getClass().getName();
        }
        return service.$invoke(method,paramTypes,para);
    }

    public Object invoke(String method,Object... para){
        String[] paramTypes = new String[para.length];
        for(int i =0; i < para.length; i++)
        {
            paramTypes[i] = para[i].getClass().getName();
        }
        return service.$invoke(method,paramTypes,para);
    }
}
